<?php require __DIR__ . '/../inc_header.tpl.php';?>

<span class="layui-breadcrumb">
    <a href="<?php echo url(['platform','platform','index']);?>">控制台</a>
    <a href="">应用模块</a>
    <a><cite>数据库工具</cite></a>
</span>

<div class="layui-tab layui-tab-brief">
  <ul class="layui-tab-title">
    <li class="layui-this"><a class="layui-this" href="<?php echo url('platform/database/index');?>">数据库管理</a></li>
  </ul>
</div>    
<br>

<div class="layui-form toolbar">
    <div class="layui-form-item">
        <div class="layui-inline">
            <a id="rj-backup" class="layui-btn">
                <i class="layui-icon layui-icon-add-1"></i>开始备份
            </a>
        </div>
    </div>
</div>
        
<table class="layui-table" id="tableTbBas" lay-filter="tableTbBas">
    <thead>
        <tr>
            <th>备份文件名</th>
            <th>文件大小</th>
            <th>备份时间</th>
            <th>操作</th>
        </tr> 
    </thead>
    <tbody>
        <?php
        foreach($dir_list as $vo){
        ?>
        <tr>
            <td ><?php echo $vo;?></td>
            <td ><?php echo round( filesize( $this->path_backup . $vo)/1024 ,2 );?>kb</td>
            <td ><?php echo date('Y-m-d H:i:s',filectime($this->path_backup . $vo));?></td>
            <td >
                <a class="layui-btn layui-btn-normal layui-btn-sm rj-restore" data-f="<?php echo $vo;?>"><i class="layui-icon layui-icon-edit"></i>还原</a>
                <a href="<?php echo url('platform/database/delete',['f'=>$vo ]);?>" onclick="return rj_confirm('确定删除备份文件？', this.href )" ><button class="layui-btn layui-btn-danger layui-btn-sm"><i class="layui-icon layui-icon-delete"></i>删除</button></a>
                <a href="<?php echo url('platform/database/down',['f'=>$vo ]);?>"><button class="layui-btn layui-btn-normal layui-btn-sm"><i class="layui-icon layui-icon-edit"></i>下载</button></a>
            </td>
        </tr>
        <?php
        }
        ?>
    </tbody>
</table>


<?php require __DIR__ . '/../inc_footer.tpl.php';?>
<!-- js部分 -->
<script>
layui.use(['layer', 'form'], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;

    // 备份
    $('#rj-backup').click(function(){

        layer.load(0,{ shade: 0.1 });
        $.getJSON( "<?php echo url('platform/database/backup');?>" ,{},function(data){
            if(data.code==1){
                layer.close(layer.index); //关闭
                location.reload();
            }
        });

    });

    // 还原
    $('.rj-restore').click(function(){
        layer.confirm( '确定还原备份文件？', {icon: 3, title:'提示'}, function(index){
            layer.close(layer.index); //关闭
            //do something
            layer.load(0,{ shade: 0.1 });
            $.getJSON( "<?php echo url('platform/database/restore');?>" ,{'f':$('.rj-restore').data('f') },function(data){
                layer.close(layer.index); //关闭
                if( data.code== 200 ){
                    layer.alert('数据还原成功。', {icon: 1,time: 3000});
                }else{
                    layer.alert('数据还原失败。', {icon: 1,time: 1500});
                }
            });
        });

    });


});
</script>